function calculationRow() {
	if (formulasRow != null && formulasRow != "" && formulasRow.length > 0) {
		for (var i = 0; i < formulasRow.length; i++) {
			var newformulasRow = $.trim(formulasRow[i]);
			if (newformulasRow != "") {
				var elementStr = newformulasRow.split(" ");
				if (elementStr != "" && elementStr.length > 0) {
					var lv = document.getElementsByName(elementStr[0]).length;
					for (var a = 0; a < lv; a++) {
						var eleLv = elementStr.length-1;
						var cal = "";
						var valid = "";
						for (var j = 0; j < eleLv-1; j++) {
							var element = elementStr[j];
							
							if (element == "+" || element == "-"
									|| element == "*" || element == "/"
									|| element == "%" || element == "("
									|| element == ")") {
								cal += element;
								if(element == "/"){
									valid = element;
								}
							} else {
								var val = document.getElementsByName(element)[a].value;
								
								cal += val;
								if(valid == "/" && val == 0){
									valid += "0";
									break;
								}
							}
						}
						var reslT = document.getElementsByName(elementStr[eleLv])[a];
						if(valid == "/0"){
							reslT.value = "";
							continue;
						}
						try{
							reslT.value = (eval(cal)).toFixed(2);
						}catch (e) {
							reslT.value = "";
							//alert(e);
						}
						
					}
				}
			}
		}
	}
	jsBackFun();
}

function enrollListener() {
	if (formulasRow != null && formulasRow != "" && formulasRow.length > 0) {
		for (var i = 0; i < formulasRow.length; i++) {
			var newformulasRow = $.trim(formulasRow[i]);
			if (newformulasRow != "") {
				var elementStr = newformulasRow.split(" ");
				if (elementStr != "" && elementStr.length > 0) {
					var lv = document.getElementsByName(elementStr[0]).length;
					for (var a = 0; a < lv; a++) {
						var eleLv = elementStr.length;
						for (var j = 0; j < eleLv-2; j++) {
							var element = elementStr[j];
							if (element == "+" || element == "-"
									|| element == "*" || element == "/"
									|| element == "%" || element == "("
									|| element == ")") {
							} else {
								var ele = document.getElementsByName(element)[a];
								if(ele.nodeName == "SELECT"){
									if (explorer.indexOf("Firefox") > 0) {
										ele.addEventListener("change", calculationRow, false);
									} else if (explorer.indexOf("Safari") > 0) {
										ele.addEventListener("change", calculationRow, false);
									} else if (explorer.indexOf("Camino") > 0) {
										ele.addEventListener("change", calculationRow, false);
									} else if (explorer.indexOf("Gecko/") > 0) {
										ele.addEventListener("change", calculationRow, false);
									} else if (explorer.indexOf("MSIE") > 0) {
										ele.attachEvent("onchange", calculationRow);
									}
								}else{
									if (explorer.indexOf("Firefox") > 0) {
										ele.addEventListener("keyup", calculationRow, false);
									} else if (explorer.indexOf("Safari") > 0) {
										ele.addEventListener("keyup", calculationRow, false);
									} else if (explorer.indexOf("Camino") > 0) {
										ele.addEventListener("keyup", calculationRow, false);
									} else if (explorer.indexOf("Gecko/") > 0) {
										ele.addEventListener("keyup", calculationRow, false);
									} else if (explorer.indexOf("MSIE") > 0) {
										ele.attachEvent("onkeyup", calculationRow);
										//onpropertychange
									}
								}
							}
						}
					}
				}
			}
		}
	}
	jsBackFun();
}
enrollListener();

function getDecimal(obj,x){
	var value1 = obj.value + "";
	if(value1 != "" && !isNaN(x) && !isNaN(value1)){
		obj.value = parseFloat(value1).toFixed(x);
	}else{
		obj.value = parseFloat("0").toFixed(x);
	}
	decimalBackFun(obj);
}

function calculationCol(){
	if (formulasCol != null && formulasCol != "" && formulasCol.length > 0) {
		for (var i = 0; i < formulasCol.length; i++) {
			var newformulasCol = $.trim(formulasCol[i]);
			if (newformulasCol != "") {
				var elementStr = newformulasCol.split(" ");
				if (elementStr != "" && elementStr.length > 0) {
					var lv = document.getElementsByName(elementStr[0]).length;
					for (var a = 0; a < lv; a++) {
						
					}
				}
			}
		}
	}
}

/**
 * 小写金额转化大写金额
 * @param num  金额
 * @returns {String}
 */
function amountLtoU(num) {
    if(isNaN(num)){
    	return "无效数值！";
    }
    var strPrefix="";
    if(num<0){
    	strPrefix ="(负)";
    }
    num=Math.abs(num);
    if(num>=1000000000000){
    	return "无效数值！";
    }
    var strOutput = "";
    var strUnit = '仟佰拾亿仟佰拾万仟佰拾元角分';
    var strCapDgt='零壹贰叁肆伍陆柒捌玖';
    num += "00";
    var intPos = num.indexOf('.');
    if (intPos >= 0){
        num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
    }
    strUnit = strUnit.substr(strUnit.length - num.length);
    for (var i=0; i < num.length; i++){
        strOutput += strCapDgt.substr(num.substr(i,1),1) + strUnit.substr(i,1);
    }
    return strPrefix+strOutput.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元");
}
